package cn.wolfcode.query;

import lombok.Getter;

import java.util.List;
@Getter
public class PageResult<T> {
    private int currentPage;
    private int pageSize;

    private int totalCount;
    private List<T> list;

    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> list) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = list;

        if(pageSize>=totalCount){
            this.totalPage=1;
            this.prevPage=1;
            this.nextPage=1;
            return;
        }

        this.totalPage=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
        this.prevPage=currentPage-1>=1?currentPage-1:1;
        this.nextPage=currentPage+1<=totalPage?currentPage+1:totalPage;
    }
}
